package com.hxalex.simulationhandle.accessbilityService.receiver.search;

import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import com.hxalex.simulationhandle.accessbilityService.manger.SearchManger;
import com.hxalex.simulationhandle.accessbilityService.receiver.base.BaseReceiver;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by hx_Alex on 2018/5/31.
 */

public class ClickWebContentReceiver extends BaseReceiver {
    private static final int DEAFLAUT_WAIT_TIME=10000;
    private boolean isblocking=false;
   

  
    
   

    public ClickWebContentReceiver(SearchManger searchManger) {
        super(searchManger);
    }


    @Override
    public void doSomething() {
        
        if(isblocking) return;
        isblocking=true;
        //获取匹配到的网站库列表
        List<AccessibilityNodeInfo> contentMatchList = searchManger.getContentMatchList();
        if(contentMatchList!=null && contentMatchList.size()>0)
        {
           
            //获取第一个网站库列表，点击后删除
            AccessibilityNodeInfo info = contentMatchList.get(0);
            if(searchManger.performActionClick(info))
           {
              Log.e("performActionClick",info.getText().toString());
               contentMatchList.remove(0);
           }
            
               
        }else
        {
            commandCompleteListener.commandCompleteListener();
            return;
        }
        int waitTime=  DEAFLAUT_WAIT_TIME+(searchManger.getWebSiteStopTime()*1000);
        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                isblocking=false;
            }
        },waitTime);
        
    }
    
    

    
    
    
   
}
